<?php
/**
 * top_banner.php
 *
 * @copyright 2018 OpenCart.cn
 *
 * All Rights Reserved
 * @link http://guangdawangluo.com
 *
 * @author stiffer.chen <chenlin@opencart.cn>
 * @created 2018-06-24 15:22
 * @modified 2018-06-24 15:22
 */
class ControllerExtensionModuleTopBanner extends Controller
{
    public function index($setting)
    {
        $position = $setting['position'];
        $route = get('route');
        $category = isset($setting['category']) && $setting['category'] ? $setting['category'] : array();
        $product = isset($setting['product']) && $setting['product'] ? $setting['product'] : array();
        if (!$route || $route == 'common/home') {
            if ($position) {
                return false;
            }
        } elseif ($route == 'product/category' && $position == 1) {
            if (!$category) {
                return false;
            }
            $path = get('path');
            $path_arr = explode('_', $path);
            $category_id = array_pop($path_arr);
            if (!in_array($category_id, $category)) {
                return false;
            }
        } elseif ($route == 'product/product' && $position == 2) {
            if (!$product) {
                return false;
            }

            $product_id = get('product_id');
            if (!$product_id || !in_array($product_id, $product)) {
                return false;
            }
        } else {
            return false;
        }

        $data['bg_color'] = $setting['color'];
        $data['link'] = $setting['link'];
        $data['bg_status'] = $setting['bg_status'];
        if ($setting['image'] && is_file(DIR_IMAGE . $setting['image'])) {
            $data['image'] = resizeImage($setting['image'], (float)$setting['width'], $setting['height']);
        } else {
            $data['image'] = resizeImage('no_image.png', (float)$setting['width'], $setting['height']);
        }
        return $this->load->view('extension/module/top_banner', $data);
    }
}